package com.woniu.service.impl;

import com.woniu.entity.Graduate1;
import com.woniu.mapper.GraduateDao;
import com.woniu.pojo.Graduate;
import com.woniu.pojo.GraduateExample;
import com.woniu.pojo.StudentExample;
import com.woniu.service.GraduateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Transactional
public class GraduateServiceImpl implements GraduateService {

    @Autowired
    private GraduateDao graduateDao;

    @Override
    public void add(Graduate graduate) {
        graduateDao.insert(graduate);
    }

    @Override
    public void deleteById(Integer graduateId) {
        graduateDao.deleteByPrimaryKey(graduateId);
    }

    @Override
    public Graduate1 findOne(Integer graduateId) {
        return graduateDao.selectByPrimaryKey1(graduateId);
    }

    @Override
    public void updateById(Graduate graduate) {
        graduateDao.updateByPrimaryKey(graduate);
    }

    @Override
    public List<Graduate1> findAll(Graduate graduate) {
        GraduateExample example = new GraduateExample();
        GraduateExample.Criteria criteria = example.createCriteria();
        if (graduate != null){
            if (graduate.getStudentId() != null){
                criteria.andStudentIdEqualTo(graduate.getStudentId());
            }
            if (graduate.getCompanyId() != null){
                criteria.andCompanyIdEqualTo(graduate.getCompanyId());
            }
        }
        return graduateDao.selectByExample1(example);
    }

    @Override
    public void deleteByExample(List<Integer> graduateIds) {
        GraduateExample example = new GraduateExample();
        example.createCriteria().andGraduateIdIn(graduateIds);
        graduateDao.deleteByExample(example);
    }
}
